import type { Metadata } from "next"; import Link from "next/link"; import { getLocale } from "@/lib/i18n/server"; import { href, t } from "@/lib/i18n"; import { facets, listPapers } from "@/lib/papers/queries"; import type { ListParams } from "@/lib/papers/types"; import { parseListParams, type SP } from "@/lib/papers/params"; import { PaperCard, PaperRow, PaperTable } from "@/components/paper-items"; import { DisplayToggle, type DisplayMode } from "@/components/display-toggle"; import { Pagination } from "@/components/pagination"; import { Suspense } from "react"; export const dynamic = "force-dynamic"; export async function generateMetadata(): Promise { const d = t(await getLocale()); return { title: d.papers.title, description: d.papers.lead, alternates: { canonical: "/papers" } }; } export default async function PapersPage({ searchParams }: { searchParams: Promise }) { const sp = await searchParams; const locale = await getLocale(); const d = t(locale); const params = parseListParams(sp); const view = (["list", "compact", "cards", "table"].includes(String(sp.view)) ? sp.view : "list") as DisplayMode; const [res, f] = await Promise.all([listPapers(params), facets()]); const qs = new URLSearchParams(); for (const [k, v] of Object.entries(sp)) if (v !== undefined && k !== "page") (Array.isArray(v) ? v : [v]).forEach((x) => qs.append(k, x)); const has = (k: keyof ListParams, v: string) => ((params[k] as string[] | number[] | undefined) ?? []).map(String).includes(v); const active = Object.entries({ year: params.year, domain: params.domain, topic: params.topic, author: params.author, keyword: params.keyword, method: params.method, dataset: params.dataset, pub: params.pubStatus, series: params.series, lang: params.lang }).filter(([, v]) => v && v.length).length + (params.pdf ? 1 : 0) + (params.q ? 1 : 0); const name = (x: { name_en: string; name_fr: string }) => (locale === "fr" ? x.name_fr : x.name_en); const Group = ({ title, k, opts }: { title: string; k: string; opts: { v: string; label: string; n: number }[] }) => opts.length ? (
{title}{opts.length}
    {opts.map((o) =>
  • )}
) : null; return (

{d.papers.title}

{d.papers.lead}

{res.total} {res.total === 1 ? d.papers.result : d.papers.results}

{[...qs.entries()].filter(([k]) => k !== "sort" && k !== "view").map(([k, v], i) => )}
{res.items.length === 0 ?

{d.papers.noResults}

: view === "cards" ?
{res.items.map((p) => )}
: view === "table" ? :
{res.items.map((p) => )}
} {(params.sort === "views" || params.sort === "downloads" || view === "table") &&

{d.papers.popularityNote}

}
); }